import QtQuick 2.4
import Qt.labs.settings 1.0

ResultPageForm {

    Settings{
        id:config
    }

    Timer{
        id:timer

        interval: config.value("ResultShowSeconds",3) * 1000

        repeat: false

        onTriggered: {

            var hasNextQuestion  = Game.hasNextRound()


            if(!hasNextQuestion){

                Game.endGame()

                stackView.replace("qrc:///Pages/ScorePage.qml")
            }
            else{
                stackView.replace("qrc:///Pages/QuestionPage.qml")
            }
        }
    }


    Component.onCompleted: {
        config.fileName  =  ApplicationPath + "/config.ini"

        console.log("Result page completed")

        var  isCorrect  = Game.isCorrect()
        console.log(isCorrect ? "正确":"错误")

        console.log("正确选项索引值", Game.rightSelectionIndex())

        var correctOption  = Game.optionAt(Game.rightSelectionIndex())
        console.log("正确选项为", correctOption)


        bgImage.source  = isCorrect ? "../Images/bk/correct.jpg" : "../Images/bk/incorrect.jpg";

        titleText.text  = "本题答案\n" + correctOption

        if(Game.selection() === 0){
            contentText.text  = "无人抢答\n进入下一题"
        }
        else{
            if(isCorrect)            {
                contentText.text  = "回答正确"
            }
            else{
                contentText.text  = "回答错误\n" + Game.optionAt(Game.selection() -1)
            }
        }


        if(!Game.hasNextRound()){
            var needPushScore  = config.value("NeedPushScore", 1)
            console.log('Need push score value is', needPushScore)
            if(needPushScore > 0)
                Game.pushScore()
        }


        timer.start()
    }
}
